home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / fielddh.exe / FIELDS_C.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-04-30  |  25.2 KB  |  685 lines

  1. {*************************************************}
  2. {                                                 }
  3. {   Turbo Pascal 6.0                              }
  4. {   Turbo Vision Forms Demo                       }
  5. {   Copyright (c) 1990 by Borland International   }
  6. {*************************************************}
  7. {                                                 }
  8. {  Original by BI, my additions are FREEWARE      }
  9. {          Doug Hood CIS 70324,3336               }
  10. {                                                 }
  11. {*************************************************}
  12. { Original Allows for                             }
  13. {   1: non-blank input lines!                     }
  14. {   2: ranged integer fields!                     }
  15. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  16. {   DWH: added Err_Msg String                     }
  17. {        added COLORS to buttons/static/input text}
  18. {        added NoEcho fields (for passwords)      }
  19. {        added UPPERCASE input lines              }
  20. {        added centered input lines               }
  21. {        added drive input lines                  }
  22. {        added path  input lines                  }
  23. {                                                 }
  24. {*************************************************}
  25.  
  26. unit Fields_Color;
  27.  
  28. {$F+,O+,X+,S-,D-}
  29.  
  30. interface
  31.  
  32. uses Objects, Drivers, Dialogs, Views,
  33.      Color_App;   {color Buttons/Text, dialogs, and field support}
  34.  
  35. type
  36.  
  37. {*************************************************************************}
  38. {*  TInputLine (TVision)                                                 *}
  39. {*        |                                                              *}
  40. {*        + Color_InputLine (in unit COLOR_APP)                          *}
  41. {*                |                                                      *}
  42. {*                + TKeyInputLine (can be invalid if empty)              *}
  43. {*                      |                                                *}
  44. {*                      + TUpper_InputLine                               *}
  45. {*                      |        |                                       *}
  46. {*                      |        + TCentered_InputLine                   *}
  47. {*                      |        |                                       *}
  48. {*                      |        + TPath_InputLine                       *}
  49. {*                      |        |                                       *}
  50. {*                      |        + TDrive_InputLine                      *}
  51. {*                      |        |                                       *}
  52. {*                      |        + TNoEcho_InputLine                     *}
  53. {*                      |        |                                       *}
  54. {*                      |        + TDate_InputLine                       *}
  55. {*                      |                                                *}
  56. {*                      + TNumInputLine                                  *}
  57. {*************************************************************************}
  58.  
  59.  
  60.   {*------------------------------------------------*}
  61.   { Same as Color_InputLine, except invalid if empty }
  62.   {*------------------------------------------------*}
  63.   PKeyInputLine = ^TKeyInputLine;
  64.   TKeyInputLine = object(COLOR_APP.Color_InputLine)
  65.     IsValid : boolean;
  66.     Blank_Is_Allowed : boolean;
  67.     constructor Init(var Bounds: TRect; AMaxLen: Integer;
  68.                      Color_Id           : word;     {0=use default}
  69.                      Empty_Allowed      : boolean);
  70.     function Valid(Command: Word): Boolean; virtual;
  71.     procedure HandleEvent (var Event : TEvent); virtual;
  72.     function GetPalette: PPalette; VIRTUAL; {for change color on error}
  73.   end; {tkeyinputline}
  74.  
  75.  
  76.   {*-------------------------------------------------*}
  77.   { Same as TKeyInputLine, except can force UPPERCASE }
  78.   {*-------------------------------------------------*}
  79.   PUpper_InputLine = ^TUpper_InputLine;
  80.   TUpper_InputLine = object(TKeyInputLine)
  81.     Force_UpperCase : boolean;
  82.     constructor Init(var Bounds: TRect; AMaxLen: Integer;
  83.                      Color_Id           : word;     {0=use default}
  84.                      Empty_Allowed      : boolean;
  85.                      Force_To_Uppercase : boolean);
  86.     procedure HandleEvent (var Event : TEvent); virtual;
  87.   end; {tupper_inputline}
  88.  
  89.  
  90.   {*--------------------------------------------------------------*}
  91.   { Same as TUpper_InputLine, except centers string as its entered }
  92.   {*--------------------------------------------------------------*}
  93.   PCentered_InputLine = ^TCentered_InputLine;
  94.   TCentered_InputLine = object(TUpper_InputLine)
  95.     Left_Justify_Allowed : boolean; {whether to look for ^LJ}
  96.     constructor Init(var Bounds: TRect; AMaxLen: Integer;
  97.                      Color_Id           : word;     {0=use default}
  98.                      Empty_Allowed      : boolean;
  99.                      Force_To_Uppercase : boolean;
  100.                      Allow_Left_Justify : boolean); {^LJ}
  101.     procedure HandleEvent (var Event : TEvent); virtual;
  102.     procedure SetData(var Rec); virtual;
  103.   end; {tcentered_inputline}
  104.  
  105.  
  106.   {*--------------------------------------------------------------*}
  107.   { Same as TUpper_InputLine, except expects full path syntax      }
  108.   { also checks if path exists and warns user if it doesnt         }
  109.   {*--------------------------------------------------------------*}
  110.   PPath_InputLine = ^TPath_InputLine;
  111.   TPath_InputLine = object(TUpper_InputLine)
  112.     function Valid(Command: Word): Boolean; virtual;
  113.   end; {tpath_inputline}
  114.  
  115.  
  116.   {*--------------------------------------------------------------*}
  117.   { Same as TUpper_InputLine, except expects a drive letter        }
  118.   { also checks if drive exists and warns user if it doesnt        }
  119.   {*--------------------------------------------------------------*}
  120.   PDrive_InputLine = ^TDrive_InputLine;
  121.   TDrive_InputLine = object(TUpper_InputLine)
  122.     Bytes_Free_Req : LongInt;
  123.     constructor Init(var Bounds: TRect; AMaxLen: Integer;
  124.                      Color_Id                : word;     {0=use default}
  125.                      Empty_Allowed           : boolean;
  126.                      Force_To_Uppercase      : boolean;
  127.                      Num_Disk_Bytes_Required : LongInt); {0=dont care}
  128.     function Valid(Command: Word): Boolean; virtual;
  129.   end; {tdrive_inputline}
  130.  
  131.  
  132.   {*---------------------------------------------------*}
  133.   { Same as TInputLine, except writes '*' for each char }
  134.   {  [very useful for passwords]                        }
  135.   {*---------------------------------------------------*}
  136.   PNoEcho_InputLine = ^TNoEcho_InputLine;
  137.   TNoEcho_InputLine = object(TUPPER_InputLine)
  138.      procedure Draw; virtual;
  139.   end; {tnoecho_inputline}
  140.  
  141.  
  142.   {*----------------------------------------------------*}
  143.   { Accepts only valid numeric input between Min and Max }
  144.   {*----------------------------------------------------*}
  145.   PNumInputLine = ^TNumInputLine;
  146.   TNumInputLine = object (TKeyInputLine)
  147.     Min: Longint;
  148.     Max: Longint;
  149.     Err_Msg_String : string[80];
  150.     constructor Init(var Bounds: TRect; AMaxLen: Integer;
  151.                      Color_Id           : word;     {0=use default}
  152.                      Empty_Allowed      : boolean;
  153.                      AMin, AMax: Longint;
  154.                      Err_Msg_Start : string);
  155.     constructor Load(var S: TStream);
  156.     function DataSize: Word; virtual;
  157.     procedure GetData(var Rec); virtual;
  158.     procedure SetData(var Rec); virtual;
  159.     procedure Store(var S: TStream);
  160.     function Valid(Command: Word): Boolean; virtual;
  161.   end; {tnuminputline}
  162.  
  163.  
  164.   {*--------------------------------------------------------------*}
  165.   { Same as TUpper_InputLine, except expects date syntax           }
  166.   { also checks if date exists and warns user if it doesnt         }
  167.   {*--------------------------------------------------------------*}
  168.   PDate_InputLine = ^TDate_InputLine;
  169.   TDate_InputLine = object(TUpper_InputLine)
  170.     Month, Day, Year : word;
  171.     function Valid(Command: Word): Boolean; virtual;
  172.     constructor Init (var Bounds: TRect; AMaxLen: Integer;
  173.                       Color_Id                : word;
  174.                       Empty_Allowed           : boolean;
  175.                       Force_To_UpperCase      : boolean;
  176.                       Default_To_ToDay        : boolean);
  177.   end; {tdate_inputline}
  178.  
  179. procedure RegisterFields;
  180.  
  181. const
  182.   RKeyInputLine: TStreamRec = (
  183.      ObjType: 10060;
  184.      VmtLink: Ofs(TypeOf(TKeyInputLine)^);
  185.      Load:    @TKeyInputLine.Load;
  186.      Store:   @TKeyInputLine.Store
  187.   );
  188.   RNumInputLine: TStreamRec = (
  189.      ObjType: 10061;
  190.      VmtLink: Ofs(TypeOf(TNumInputLine)^);
  191.      Load:    @TNumInputLine.Load;
  192.      Store:   @TNumInputLine.Store
  193.   );
  194.   {*----------------------------------------------------------------*}
  195.   {* NOTE: the new fields arent TStreamed, unless someone out there *}
  196.   {*       wants to help????                                        *}
  197.   {*----------------------------------------------------------------*}
  198.  
  199.  
  200. {***********************************************************************}
  201. {***********************************************************************}
  202. {***********************************************************************}
  203. implementation
  204.  
  205. uses MsgBox,
  206.      Str_Stf,
  207.      File_Lib,
  208.      Dates,   {for date valid check}
  209.      DOS;
  210.  
  211. {************************************************************************}
  212. procedure RegisterFields;
  213. begin
  214.   RegisterType(RKeyInputLine);
  215.   RegisterType(RNumInputLine);
  216. end;
  217.  
  218. { TKeyInputLine }
  219. {************************************************************************}
  220. function TKeyInputLine.Valid(Command: Word): Boolean;
  221. begin
  222.   IsValid := True;
  223.   if ((Command <> cmCancel) and (Command <> cmValid) and
  224.        (NOT Blank_Is_Allowed)) then
  225.   begin
  226.     if Data^ = '' then
  227.     begin
  228.       IsValid := False;
  229.       Select;
  230.       MessageBox('This field cannot be Empty.', nil, mfError + mfOkButton);
  231.     end;
  232.   end;
  233.   if IsValid
  234.     then Valid := TInputLine.Valid(Command)
  235.     else Valid := FALSE;
  236. end; {valid}
  237.  
  238. {************************************************************************}
  239. procedure TKeyInputLine.HandleEvent (var Event : TEvent);
  240. begin
  241.   IsValid := TRUE;  {for no flash when leave field}
  242.   Color_InputLine.HandleEvent (Event);
  243. end; {handleevent}
  244.  
  245. {************************************************************************}
  246. function TKeyInputLine.GetPalette: PPalette;
  247. var
  248.  AltPalette: String[Length(CInputLine)];
  249. begin
  250.      { By assigning a palette index number that is out of the range of
  251.        our owner's palette, we automatically get flashing white on red
  252.        for this color entry.}
  253.   AltPalette := Color_InputLine.GetPalette^;
  254.   if (NOT IsValid)
  255.     then AltPalette[1] := #255;    {pos 1 is the PASSIVE color}
  256.   GetPalette := @AltPalette;
  257. end;
  258.  
  259.  
  260.  
  261. {************************************************************************}
  262. constructor TKeyInputLine.Init (var Bounds: TRect; AMaxLen: Integer;
  263.                                 Color_Id           : word;
  264.                                 Empty_Allowed       : boolean);
  265. begin
  266.   Color_InputLine.Init (Bounds, AMaxLen, Color_Id);
  267.   Blank_Is_Allowed := Empty_Allowed;
  268.   IsValid := TRUE;{Valid(cmOk);}
  269. end; {upper}
  270.  
  271. {************************************************************************}
  272. constructor TUpper_InputLine.Init (var Bounds: TRect; AMaxLen: Integer;
  273.                                     Color_Id           : word;
  274.                                     Empty_Allowed      : boolean;
  275.                                     Force_To_Uppercase : boolean);
  276. begin
  277.   TKeyInputLine.Init (Bounds, AMaxLen, Color_Id, Empty_Allowed);
  278.   Force_UpperCase := Force_To_Uppercase;
  279. end; {upper}
  280.  
  281. {***********************************************************************}
  282. procedure TUpper_InputLine.HandleEvent(var Event: TEvent);
  283. begin
  284.   IF ((Force_UpperCase) and
  285.       ((Event.What = evKeyDown) and
  286.        (Event.CharCode in ['a'..'z'])))
  287.     THEN Event.CharCode := CHR((ORD(Event.CharCode) - 32));
  288.  
  289.   TKeyInputLine.HandleEvent(Event);
  290.  
  291. end; {handleevent}
  292.  
  293.  
  294. {************************************************************************}
  295. constructor TCentered_InputLine.Init (var Bounds: TRect; AMaxLen: Integer;
  296.                                      Color_Id           : word;
  297.                                      Empty_Allowed      : boolean;
  298.                                      Force_To_Uppercase : boolean;
  299.                                      Allow_Left_Justify : boolean);
  300. begin
  301.   TUpper_InputLine.Init (Bounds, AMaxLen, Color_Id,
  302.                         Empty_Allowed, Force_To_Uppercase);
  303.   Left_Justify_Allowed := Allow_Left_Justify;
  304. end; {centered}
  305.  
  306. {***********************************************************************}
  307. procedure TCentered_InputLine.HandleEvent(var Event: TEvent);
  308. var
  309.   Center_Me        : boolean;
  310.   Num_Trail_Blanks : integer;
  311.   Temp_Str         : string;
  312.   Temp_Pos         : integer;
  313. begin
  314.   {*----------------------------------------------------------------*}
  315.   {* To speed things up, limit 'CENTERING' to be done only when     *}
  316.   {* necessary.                                                     *}
  317.   {*----------------------------------------------------------------*}
  318.   IF ((Event.What = evKeyDown) and
  319.           ((ORD(Event.CharCode) > 0) OR
  320.            (Event.Command = kbBack) OR       {backspace}
  321.            (Event.Command = kbDel)) )        {multi char delete}
  322.     THEN Center_Me := TRUE
  323.     ELSE Center_Me := FALSE;
  324.  
  325.   TUpper_InputLine.HandleEvent(Event);
  326.  
  327.   IF ((Center_Me) and (Left_Justify_Allowed)) THEN
  328.     BEGIN
  329.       Temp_Str := Trim_Leading_Only(Data^);
  330.       IF ((LENGTH(Temp_Str) > 2) and (Temp_Str[1] = '^') and
  331.           (Change_Case(Copy(Temp_Str,2,2)) = 'LJ')) THEN
  332.         BEGIN
  333.           Center_Me := FALSE;
  334.           Data^ := Temp_Str;
  335.           CurPos := LENGTH(Temp_Str);
  336.           IF (CurPos > MaxLen)
  337.             THEN CurPos := MaxLen;
  338.         END;
  339.     END; {if}
  340.  
  341.   IF (Center_Me) THEN
  342.     BEGIN
  343.       Temp_Str := Data^;
  344.       Num_Trail_Blanks := LENGTH(Temp_Str);
  345.       Temp_Str := Trim_Trailing_Only (Temp_Str);
  346.       Num_Trail_Blanks := Num_Trail_Blanks - LENGTH (Temp_Str);
  347.  
  348.       Temp_Pos := CurPos;
  349.       Temp_Str := Str_Stf.Trim_Trailing_Only (
  350.                                    Str_Stf.Center_Str (Temp_Str, MaxLen));
  351.       IF (Num_Trail_Blanks > 0) THEN
  352.         BEGIN
  353.           IF ((Num_Trail_Blanks + LENGTH (Temp_Str)) > MaxLen)
  354.             THEN Num_Trail_Blanks := MaxLen - LENGTH (Temp_Str);
  355.           IF (Num_Trail_Blanks > 0)
  356.             THEN Temp_Str := Temp_Str + Fill_String (Num_Trail_Blanks, ' ');
  357.         END; {if}
  358.  
  359.       IF (Data^ <> Temp_Str) THEN
  360.         BEGIN
  361.           IF (Temp_Pos > 0) THEN
  362.             BEGIN  {* must recalculate position of curpos *}
  363.               CurPos := Temp_Pos +
  364.                   (LENGTH(Temp_Str) - LENGTH(Data^));
  365.               IF (CurPos > MaxLen)
  366.                 THEN CurPos := MaxLen;
  367.             END; {if}
  368.           Data^ := Temp_Str;
  369.           DrawView; {since now centered}
  370.         END; {if}
  371.     END; {if center_me}
  372. end; {handleevent}
  373.  
  374. {************************************************************************}
  375. procedure TCentered_InputLine.SetData(var Rec);
  376. var
  377.   Temp_Str : string;
  378.   Do_It    : boolean;
  379. begin
  380.   IF (Left_Justify_Allowed) THEN
  381.     BEGIN
  382.       Temp_Str := TRIM(STRING(Rec));
  383.       IF ((LENGTH(Temp_Str) > 2) and (Temp_Str[1] = '^') and
  384.           (Change_Case(Copy(Temp_Str,2,2)) = 'LJ'))
  385.         THEN Do_It := FALSE
  386.         ELSE Do_It := TRUE;
  387.     END
  388.   ELSE Do_It := TRUE;
  389.  
  390.   IF (Do_It)
  391.     THEN Data^ := Str_Stf.Trim_Trailing_Only(
  392.                         Str_Stf.Center_Str (STRING(Rec), MaxLen))
  393.     ELSE Data^ := STRING(Rec);
  394.   SelectAll(True);
  395. end; {setdata}
  396.  
  397.  
  398. {************************************************************************}
  399. { TNumInputLine }
  400. constructor TNumInputLine.Init(var Bounds: TRect; AMaxLen: Integer;
  401.                                Color_Id           : word;
  402.                                Empty_Allowed      : boolean;
  403.                                AMin, AMax: Longint;
  404.                                Err_Msg_Start : string);
  405. begin
  406.   TKeyInputLine.Init (Bounds, AMaxLen, Color_ID, Empty_Allowed);
  407.   {TInputLine.Init (Bounds, AMaxLen);}
  408.   Min := AMin;
  409.   Max := AMax;
  410.   Err_Msg_String := Str_Stf.Trim (Err_Msg_Start);
  411.   IF (LENGTH(Err_Msg_String) = 0)
  412.     THEN Err_Msg_String := 'Number';
  413. end;
  414.  
  415. {************************************************************************}
  416. constructor TNumInputLine.Load(var S: TStream);
  417. begin
  418.   Color_InputLine.Load(S);
  419.   {TInputLine.Load(S);}
  420.   S.Read(Min, SizeOf(LongInt) * 2);
  421. end;
  422.  
  423. {************************************************************************}
  424. function TNumInputLine.DataSize: Word;
  425. begin
  426.   DataSize := SizeOf(LongInt);
  427. end;
  428.  
  429. {************************************************************************}
  430. procedure TNumInputLine.GetData(var Rec);
  431. var
  432.   Code: Integer;
  433. begin
  434.   Val(Data^, Longint(Rec), Code);
  435. end;
  436.  
  437. {************************************************************************}
  438. procedure TNumInputLine.Store(var S: TStream);
  439. begin
  440.   Color_InputLine.Store(S);
  441.   {TInputLine.Store(S);}
  442.   S.Write(Min, SizeOf(Longint) * 2);
  443. end;
  444.  
  445. {************************************************************************}
  446. procedure TNumInputLine.SetData(var Rec);
  447. var
  448.   S: string[11];
  449. begin
  450.   Str(Longint(Rec), S);
  451.   Data^ := S;
  452.   SelectAll(True);
  453. end;
  454.  
  455. {************************************************************************}
  456. function TNumInputLine.Valid(Command: Word): Boolean;
  457. var
  458.   Code: Integer;
  459.   Value: Longint;
  460.   Params: array[0..1] of LongInt;
  461. begin
  462.   IsValid := True;
  463.   if (Command <> cmCancel) and (Command <> cmValid) then
  464.   begin
  465.     if Data^ = '' then Data^ := '0';
  466.     IsValid := TKeyInputLine.Valid(Command);
  467.     if (IsValid) then
  468.       begin
  469.         Val (Data^, Value, Code);
  470.         if ((Code <> 0) or (Value < Min) or (Value > Max)) then
  471.           begin
  472.             IsValid := False;
  473.             Select;
  474.             {SelectAll(True);}
  475.             Params[0] := Min;
  476.             Params[1] := Max;
  477.             MSGBOX.MessageBox (Err_Msg_String+' must be from %D to %D.',
  478.                               @Params, mfError + mfOkButton);
  479.             {SelectAll(True);}
  480.           end;
  481.       end;
  482.     end;
  483.   Valid := IsValid;
  484. end; {valid}
  485.  
  486.  
  487. {************************************************************************}
  488. procedure TNoEcho_InputLine.Draw;
  489. var
  490.   Org_Str : String;
  491.   i       : integer;
  492. begin
  493.   IF (LENGTH(Data^) > 0) THEN
  494.     BEGIN
  495.       {GetMem (Org_Str, MaxLen + 1);       {DWH 01-06-92}
  496.       Org_Str := Data^;
  497.       Data^ := Fill_String (Length(Data^), '*');
  498.       {FOR i := 1 to LENGTH (Data^)
  499.         DO Data^[i] := '*';}
  500.       TUpper_InputLine.Draw;
  501.       {FreeMem (Data, MaxLen + 1);         {DWH 01-06-92}
  502.       Data^ := Org_Str;
  503.     END
  504.   ELSE TUpper_InputLine.Draw;
  505. end; {draw}
  506.  
  507. {************************************************************************}
  508. function TPath_InputLine.Valid(Command: Word): Boolean;
  509. var
  510.   Reply     : word;
  511.   Status    : integer;
  512.   Temp_Str  : string;
  513. begin
  514.   IsValid := True;
  515.   if (Command <> cmCancel) and (Command <> cmValid) then
  516.   begin
  517.     IsValid := TUpper_InputLine.Valid(Command);
  518.     Temp_Str := TRIM (Data^);
  519.     if ((IsValid) and NOT (Temp_Str = '')) then
  520.       BEGIN
  521.         FILE_LIB.Check_Valid_Path (Temp_Str, Status);
  522.         IF (Status <> 0) THEN
  523.           BEGIN
  524.             IsValid := False;
  525.             Select;
  526.           END; {if}
  527.  
  528.         CASE Status OF        (*   -1  is a blank handled already *)
  529.           -2 : MessageBox ('This PATH field must end with a "\"', nil,
  530.                            mfError + mfOkButton);
  531.           -3 : MessageBox ('This field must contain the DRIVE Letter.'+
  532.                            '(ex: C:\) ', nil,
  533.                             mfError + mfOkButton);
  534.           -4 : MessageBox ('This field must contain at least one "\".'+
  535.                            '(ex: C:\) ', nil,
  536.                            mfError + mfOkButton);
  537.           -5 : BEGIN
  538.                  Reply := Messagebox
  539.                                 ('Path ('+Temp_Str+') not exist!'+
  540.                                  #13'Want to Fix It?',nil,
  541.                                  mfError+mfYesButton+MfNoButton);
  542.                 IF (Reply <> cmNo)
  543.                   THEN IsValid := FALSE {to allow for change}
  544.                   ELSE IsValid := TRUE;
  545.               END; {-4}
  546.         END; {case}
  547.       END; {if}
  548.   end;
  549.   Valid := IsValid;
  550. end; {valid}
  551.  
  552. {************************************************************************}
  553. constructor TDrive_InputLine.Init (var Bounds: TRect; AMaxLen: Integer;
  554.                                    Color_Id                : word;
  555.                                    Empty_Allowed           : boolean;
  556.                                    Force_To_Uppercase      : boolean;
  557.                                    Num_Disk_Bytes_Required : LongInt);
  558. begin
  559.   TUpper_InputLine.Init (Bounds, AMaxLen, Color_Id,
  560.                          Empty_Allowed, Force_To_Uppercase);
  561.   Bytes_Free_Req := Num_Disk_Bytes_Required;
  562. end; {init}
  563.  
  564. {************************************************************************}
  565. function TDrive_InputLine.Valid(Command: Word): Boolean;
  566. var
  567.   Free_Space : LongInt;
  568.   Reply      : word;
  569.   Temp_Str   : string;
  570. begin
  571.   IsValid := True;
  572.   if (Command <> cmCancel) and (Command <> cmValid) then
  573.   begin
  574.     IsValid := TUpper_InputLine.Valid(Command);
  575.     Temp_Str := TRIM (Data^);
  576.     if ((IsValid) and NOT (Temp_Str = '')) then
  577.       BEGIN
  578.         IF (LENGTH(Temp_Str) <> 1) THEN
  579.           BEGIN
  580.             IsValid := False;
  581.             Select;
  582.             MessageBox ('This field must contain only the DRIVE Letter.'+
  583.                         '(ex: "C"   not "C:\") ', nil,
  584.                         mfError + mfOkButton);
  585.           END
  586.         ELSE IF ((ORD(Temp_Str[1]) < 65) and
  587.                  (ORD(Temp_Str[1]) > 90)) THEN
  588.           BEGIN
  589.             IsValid := False;
  590.             Select;
  591.             MessageBox ('This field must contain a DRIVE Letter.'+
  592.                         '(ex: A..Z) ', nil,
  593.                         mfError + mfOkButton);
  594.           END
  595.         ELSE
  596.           BEGIN {* Looks ok, check if drive exists *}
  597.             Free_Space := DOS.DiskFree (ORD(Temp_Str[1])-64);
  598.             IF (Free_Space = -1) THEN
  599.               BEGIN
  600.                 IF (Bytes_Free_Req <> 0) THEN
  601.                   BEGIN
  602.                     IsValid := False;
  603.                     Select;
  604.                     Messagebox ('DRIVE ('+Temp_Str+') not exist!',nil,
  605.                                 mfError+mfOkButton);
  606.                   END
  607.                 ELSE
  608.                   BEGIN
  609.                     IsValid := False;
  610.                     Select;
  611.                     Reply := Messagebox
  612.                                 ('DRIVE ('+Temp_Str+') not exist!'+
  613.                                  #13'Want to Fix It?',nil,
  614.                                  mfError+mfYesButton+MfNoButton);
  615.                     IF (Reply <> cmNo)
  616.                       THEN IsValid := FALSE {to allow for change}
  617.                       ELSE IsValid := TRUE;
  618.                   END;
  619.               END
  620.             ELSE IF ((Bytes_Free_Req > 0) and
  621.                      (Free_Space < Bytes_Free_Req)) THEN
  622.               BEGIN
  623.                 IsValid := False;
  624.                 Select;
  625.                 Messagebox ('DRIVE '+Temp_Str+' has '+Int_To_Str(Free_Space)+
  626.                             ' bytes free BUT '+Int_To_Str(Bytes_Free_Req)+
  627.                             ' free bytes are required!',nil,
  628.                             mfError+mfOkButton);
  629.               END;
  630.           END;
  631.       END; {if}
  632.   end;
  633.   Valid := IsValid;
  634. end; {valid}
  635.  
  636. {************************************************************************}
  637. constructor TDate_InputLine.Init (var Bounds: TRect; AMaxLen: Integer;
  638.                                   Color_Id                : word;
  639.                                   Empty_Allowed           : boolean;
  640.                                   Force_To_Uppercase      : boolean;
  641.                                   Default_To_ToDay        : boolean);
  642. begin
  643.   TUpper_InputLine.Init (Bounds, AMaxLen, Color_Id,
  644.                          Empty_Allowed, Force_To_Uppercase);
  645.   IF (Default_To_Today)
  646.     THEN Data^ := DATES.MDYR_Str (0,0,0);
  647.   Year  := 0;
  648.   Month := 0;
  649.   Day   := 0;
  650. end; {init}
  651.  
  652.  
  653. {************************************************************************}
  654. function TDate_InputLine.Valid(Command: Word): Boolean;
  655. var
  656.   Reply     : word;
  657.   Status    : integer;
  658.   Temp_Str  : string;
  659.   Err_Str   : string;
  660. begin
  661.   IsValid := True;
  662.   if (Command <> cmCancel) and (Command <> cmValid) then
  663.   begin
  664.     IsValid := TUpper_InputLine.Valid(Command);
  665.     Temp_Str := TRIM (Data^);
  666.     IF ((IsValid) and NOT (Temp_Str = '')) then
  667.       BEGIN
  668.         IsValid := DATES.ValidDate_Str (Temp_Str,
  669.                                         Year,Month,Day,
  670.                                         Err_Str);
  671.         IF (IsValid)
  672.           THEN Data^ := DATES.MDYR_Str (Year, Month, Day)
  673.         ELSE MessageBox (Err_Str, nil, mfError + mfOkButton);
  674.       END;
  675.   end;
  676.  
  677.   IF (NOT IsValid)
  678.     THEN Select;
  679.  
  680.   Valid := IsValid;
  681. end; {valid}
  682.  
  683.  
  684.  
  685. end. {unit FIELDS_Color}